package cate.game.play.skill.passive.hero;

import cate.common.table.d.GDAttr;
import cate.common.table.d.GDSkill;
import cate.common.util.XT;
import cate.game.attr.FightAttr;
import cate.game.play.buff.Buff;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.skill.effect.SkillEffect;
import cate.game.play.skill.passive.PassiveHandler;

import java.util.List;

/**
 * 攻击时有75%概率使目标身上随机1个增益状态转化为【诅咒】，
 * 目标身上每存在1层【诅咒】，自身攻击造成的伤害提升5%，最多可提升25%/n无冷却时间
 */
public class 深海诅咒PH extends PassiveHandler {

	private int 概率;

	private int 诅咒buff;

	private double 伤害;

	private double 最大伤害;

	//概率=7500&诅咒buff=？？&伤害=500&最大伤害=2500
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		概率 = args.getInt("概率", 0);
		诅咒buff = args.getInt("诅咒buff", 0);
		伤害 = args.getDouble("伤害", 0d);
		最大伤害 = args.getDouble("最大伤害", 0d);
	}

	@Override
	public void parseExt(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		概率 += args.getInt("概率", 0);
	}

	@Override
	public void beforeSkillSettleAsActor(SkillActionCtx action, SkillEffect effect, Fighter target) {
		if (!action.getSkill().cfg.isEffectType(GDSkill.EffectType.伤害)) {
			return;
		}
		if (XT.chance(概率)) {
			List<Buff> buffs = target.buff.tryDispel(action, Buff::isGood, 1);
			if (XT.isNotBlank(buffs)) {
				target.buff.tryAddByTid(action,skill.owner, 诅咒buff);
			}
		}
		int buffNum = target.buff.countBuffByTid(诅咒buff);
		if (buffNum > 0) {
			effect.getTargetCtx(target.getPid()).
					addActorAttr(new FightAttr(GDAttr.DAMAGE_ADD, Math.min(buffNum * 伤害, 最大伤害)));
		}
	}
}
